// 计时器
type TimerCallback = (index: number) => void;

export default class TimerUtil {
  /**
   * 启动x次的定时器
   * @param count 循环次数
   * @param delay 延时/毫秒
   * @param callback
   */
  static start(count: number, delay: number, callback: TimerCallback): number {
    let index = 0
    const timerId = setInterval(() => {
      callback(index)
      if (index > count) {
        clearInterval(timerId)
      }
    }, delay)
    return timerId
  }

}
